import java.util.Vector;

/**
 * User: Henry Abravanel
 * Date: 10/06/11
 * Time: 00:25
 */
public class HistoryStream implements Stream {
    private int count = -1;
    private Vector<String> history = new Vector<String>();

    @Override
    public String next() {
        String res = null;
        if (count < history.size() - 1) {
            count++;
            res = history.elementAt(count);
        }
        return res;
    }

    @Override
    public String prev() {
        String res = null;
        if (count > -1) {
            count--;
        }
        if (count >= 0) {
            res = history.get(count);
        }
        return res;
    }

    public void reset() {
        history.clear();
        count = -1;
    }

    public void add(String res) {
        if (count < history.size()) {
            count++;
        }
        if (res != null) {
            history.add(res);
        }
    }

    public int size() {
        return history.size();
    }
}
